﻿
#foreach($u in $TableInfos)
#beforeall 
#each 
#foreach($c in $u.ColumnInfos)  
#beforeall
#set($tmp1="") #set($tmp2="")#set($tmp3="")#set($tmpPK="")#set($tbCount=0)
#each 
#if($c.IsPK=="True") #set($tmpPK="$c.ColumnName=@$c.ColumnName")#end
#if($tbCount==0)
#set($tmp1=$c.ColumnName)#set($tmp2="@$c.ColumnName")
#if($c.IsPK!="True")
#set($tmp3="$c.ColumnName=@$c.ColumnName")
#end
#else
#set($tmp1="$tmp1,$c.ColumnName") #set($tmp2="$tmp2,@$c.ColumnName")
#if($c.IsPK!="True")
#if($tmp3!="")
#set($tmp3="$tmp3,$c.ColumnName=@$c.ColumnName")
#else
#set($tmp3="$c.ColumnName=@$c.ColumnName")
#end
#end
#end
#if($c.IsPK!="True")
#set($tbCount=$tbCount+1)
#end
#afterall
#end
#region "$u.TabName ($u.TabCaption ) - DataProvider"
/// <summary>
/// 新增/删除/修改 ${u.TabName}Entity ($u.TabCaption)
/// </summary>
/// <param name="fam">$u.TabName实体类</param>
/// <returns>-1:存储过程执行失败,-2:存在相同的主键,Insert:返回插入自动ID,Update:返回更新记录数,Delete:返回删除记录数</returns>
public Int32 ${u.TabName}InsertUpdateDelete(${u.TabName}Entity fam)
{
#foreach($c in $u.ColumnInfos)  
#beforeall
#set($tbCount=0)#set( $listCount=$u.ColumnInfos.Count)#set( $listCount=$listCount - 1 )
 Int32 rInt = -1;
 string CommTxt = string.Empty;
 DbParameter[] prams;
 if (fam.DataTable_Action.ToString() == "Insert")
 { 
  prams = new DbParameter[ $listCount ];
  CommTxt = "Insert into $u.TabName ( $tmp1 )VALUES($tmp2)";
#each 
#if($c.IsPK!="True")
  prams[$tbCount] = CreateInDbParameter("$c.ColumnName", MyDBType.$c.TypeDbName, fam.$c.ColumnName);//$c.DeText 
#set($tbCount=$tbCount+1)
#end
#afterall
 }
#end
#foreach($c in $u.ColumnInfos)  
#beforeall
#set($tbCount=0)#set( $listCount=$u.ColumnInfos.Count)
 else if (fam.DataTable_Action.ToString() == "Update")
 {
  prams = new DbParameter[$listCount];
  CommTxt = "UPDATE $u.TabName SET $tmp3  WHERE ($tmpPK)";
#each
  prams[$tbCount] = CreateInDbParameter("$c.ColumnName", MyDBType.$c.TypeDbName, fam.$c.ColumnName);//$c.DeText 
#set($tbCount=$tbCount+1)
#afterall
 }
#end
 else if (fam.DataTable_Action.ToString() == "Delete")
 {
 
#foreach($c in $u.ColumnInfos)  
#beforeall
  prams = new DbParameter[1];
  CommTxt = "Delete from  $u.TabName  WHERE ($tmpPK)";
#each
#if($c.IsPK=="True")
  prams[0] = CreateInDbParameter("$c.ColumnName", MyDBType.$c.TypeDbName, fam.$c.ColumnName);//$c.DeText 
#end             
#afterall
#end

 }
 else
 throw new ApplicationException("无法识别的操作命令!");
 rInt = dbHelper.ExecuteNonQuery(connectionString, CommandType.Text,CommTxt, prams);
 return rInt;
}
/// <summary>
/// 返回${u.TabName}Entity 实体类的List对象 ($u.TabCaption )
/// </summary>
/// <param name="qp">查询类(非安全函数,传入参数请进行Sql字符串过滤)</param>
/// <param name="isReturnCount">是否返回记录总数</param>
/// <param name="RecordCount">返回记录总数</param>
/// <returns>$u.tmpEntity实体类的List对象($u.TabCaption)</returns>
public List<${u.TabName}Entity> ${u.TabName}List (QueryParam qp, bool isReturnCount, out int RecordCount)
{

    PopulateDelegate<${u.TabName}Entity> mypd = new PopulateDelegate<${u.TabName}Entity>(this.Populate${u.TabName}Entity);
    return this.GetRecordList(mypd, qp, isReturnCount, out RecordCount);
}

/// <summary>
/// 将记录集转为${u.TabName}Entity实体类 ($u.TabCaption)
/// </summary>
/// <param name="dr">记录集</param>
/// <param name="Fileds">字段名列表</param>
/// <returns>${u.TabName}Entity</returns>
protected ${u.TabName}Entity Populate${u.TabName}Entity (IDataReader dr, Dictionary<string, string> Fileds)
{
    ${u.TabName}Entity nc = new ${u.TabName}Entity();
#foreach($c in $u.ColumnInfos)  
#beforeall
#each
  if (Fileds.ContainsKey("$c.ColumnName".ToUpper()) && !Convert.IsDBNull(dr["$c.ColumnName"]))  nc.$c.ColumnName=#if($c.TypeCSharpName=="String")
dr["$c.ColumnName"].ToString(); //$c.DeText
#else
 $c.TypeCSharpName .Parse(dr["$c.ColumnName"].ToString()); //$c.DeText
#end
#afterall
#end
    
    return nc;
}
#endregion
#afterall

#nodata
暂无用户资料
#end 


